package com.example.kafkalistener.controller;

import com.alibaba.fastjson.JSON;
import com.example.kafkalistener.pojo.R;
import com.example.kafkalistener.pojo.ResData;
import edu.liuzihao.pojo.GenderOfPerson;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Liu
 * @date 2022/12/9 9:22
 **/
@RestController
@RequestMapping("/spark")
public class AllController {

    @GetMapping("/getAllPeople")
    public R getAllPeople() {
        System.out.println("这里是getAllPeople接口");
        System.out.println(ResData.AllPeopleList);
        if (ResData.AllPeopleList != null) {
                try {
                    return R.ok().put("result", ResData.AllPeopleList);
                } catch (Exception e) {
                }
        }
        return R.error();
    }

    @GetMapping("/getSchool")
    public R getSchool() {
        System.out.println("这里是School接口");
        List<JSON> result = new ArrayList<>();
        if (ResData.SchollList != null) {
            for (JSON res : ResData.SchollList) {
                try {
                    result.add(res);
                } catch (Exception e) {
                }
            }
            ResData.SchollList.clear();
        }
        return R.ok().put("result", result);
    }

    @GetMapping("/getGrade")
    public R getGrade() {
        System.out.println("这里是Grade接口");
        List<JSON> result = new ArrayList<>();
        if (ResData.GradeList != null) {
            for (JSON res : ResData.GradeList) {
                try {
                    result.add(res);
                } catch (Exception e) {
                }
            }
            ResData.GradeList.clear();
        }
        return R.ok().put("result", result);
    }
}
